package com.hh.core.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.hh.core.interceptor.ShiroPermissionInterceptor;
import com.hh.core.property.ShiroProperty;

/**
 * @author xn-h
 * @describe(Web 相关配置)
 * @create 2018/1/20
 **/
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

	@Autowired
	ShiroProperty shiroProperty;

	/**
	 * @describe (注册拦截器)
	 * @author xn-h
	 * @create 2018/1/20
	 * @param [registry]
	 * @return void
	**/
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		//注册session过期拦截器
		registry.addInterceptor(new ShiroPermissionInterceptor())
				.addPathPatterns(shiroProperty.getAuthcUrl());
//				.excludePathPatterns(shiroProperty.getAnonUrl().split(","));
	}

	/*
	 * @describe (增加 方法层 参数校验)
	 * @author xn-h
	 * @create 2018/1/21
	 * @param []
	 * @return org.springframework.validation.beanvalidation.MethodValidationPostProcessor
	**/
	@Bean
	public MethodValidationPostProcessor methodValidationPostProcessor() {
		return new MethodValidationPostProcessor();
	}
}
